<template>
  <!-- 搜索历史记录 -->
  <el-dialog
    title="搜索历史"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    width="70%"
  >
    <el-table
      :data="historyData"
      style="width: 100%"
      @cell-click="handleCellClick"
    >
      <el-table-column type="index" label="序号" width="60"> </el-table-column>
      <el-table-column prop="eSearch" label="历史记录"> </el-table-column>
    </el-table>
    <el-pagination
      class="elpagination"
      hide-on-single-page
      background
      layout="prev, pager, next"
      :current-page.sync="searchInfo.ipi"
      :page-size="searchInfo.ips"
      :total="total"
      @current-change="handleCurrentChange"
    >
    </el-pagination>
    <span slot="footer">
      <el-button @click="dialogVisible = false">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    searchTxt: {
      type: String,
    },
  },
  data() {
    return {
      dialogVisible: false,
      historyData: [],
      searchInfo: {
        ipi: 1,
        ips: 10,
      },
      total: 0,
    };
  },
  mounted() {},
  methods: {
    init() {
      this.dialogVisible = true;
      this.handleCurrentChange(1);
    },
    handleCurrentChange(val) {
      this.searchInfo.ipi = val;
      this.search();
    },
    search() {
      this.$get(`${this.$Url.search.historyList}`, this.searchInfo).then(
        (res) => {
          let data = res.data;
          // console.log("data", data);
          if (data) {
            this.historyData = data.result;
            this.total = data.total;
          }
        }
      );
    },
    handleCellClick(row, column) {
      // console.log("row", row);
      if (column.property == "eSearch") {
        this.dialogVisible = false;
        const obj = { key: row.eSearch };
        this.$emit("chooseTips", obj);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.elpagination {
  margin-top: 20px;
}
</style>
